package com.his.controller;

import com.his.common.PageParam;
import com.his.common.Rsp;
import com.his.entity.DrawbackMedicinal;
import com.his.service.DrawbackMedicinalService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (DrawbackMedicinal)表控制层
 *
 * @author makejava
 * @since 2020-10-23 18:09:37
 */
@RestController
@RequestMapping("drawbackMedicinal")
public class DrawbackMedicinalController {
    /**
     * 服务对象
     */
    @Resource
    private DrawbackMedicinalService drawbackMedicinalService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public DrawbackMedicinal selectOne(Integer id) {
        return this.drawbackMedicinalService.queryById(id);
    }

    /**
     * 增加退药申请单
     */
    //@RequireRoles(roles = "medicinal",index = 0)
    @PostMapping("insertOne")
    public Rsp insertOne (@RequestBody DrawbackMedicinal drawbackMedicinal){
        DrawbackMedicinal insert = drawbackMedicinalService.insert(drawbackMedicinal);
        if (StringUtils.isEmpty(insert)){
            return Rsp.fail().msg("单号已经退药,请勿重复添加");
        }
        return Rsp.success(insert).msg("添加成功");
    }

    /*
     *删除退药申请单
     */
    @DeleteMapping("deleteOne")
    public Rsp deleteByIdLogic(Integer id){
        if (drawbackMedicinalService.deleteByIdLogic(id)){
            return Rsp.success(null).msg("删除成功");
        }else{
            return Rsp.fail().msg("当前订单不存在,删除失败");
        }
    }

    /**
     * 修改退药申请单
     */
    @PutMapping("updateOne")
    public Rsp updateOne(@RequestBody DrawbackMedicinal drawbackMedicinal){
        DrawbackMedicinal update = drawbackMedicinalService.update(drawbackMedicinal);
        if (StringUtils.isEmpty(update)){
            return Rsp.fail().msg("请勿修改单号,修改失败");
        }
        return Rsp.success(update).msg("修改成功");
    }

    /**
     * 查询退药申请单药品列表
     */
    @PostMapping("searchSomeDrawbackMedicinalPage")
    public Rsp searchSomeDrawbackMedicinalPage(@RequestBody PageParam<DrawbackMedicinal> pageParam){
        return Rsp.success(drawbackMedicinalService.queryAll(pageParam));
    }

    /**
     *驳回退药
     */
    @PostMapping("medicinalFuse")
    public Rsp handelmedicinalFuse(@RequestBody DrawbackMedicinal drawbackMedicinal){
        return drawbackMedicinalService.handelmedicinalFuse(drawbackMedicinal);
    }

    /**
     * 同意退药
     */
    @PostMapping("medicinalSure")
    public Rsp handelmedicinalSure(@RequestBody DrawbackMedicinal drawbackMedicinal){
        return drawbackMedicinalService.handelmedicinalSure(drawbackMedicinal);
    }
}
